package com.glut.campusrepair.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.glut.campusrepair.entity.MaterialsManage;
import com.glut.campusrepair.service.IMaterialsManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 材料管理表 前端控制器
 *
 * @author sanminzhi
 * @since 2024-07-19 11:26
 */
@RestController
@Slf4j
public class MaterialsManageController {

    private final IMaterialsManageService iMaterialsManageService;

    @Autowired
    public MaterialsManageController(IMaterialsManageService iMaterialsManageService){
        this.iMaterialsManageService = iMaterialsManageService;
    }

    @GetMapping("/mm/getData")
    public List<MaterialsManage> getMaterialsManage(){
        return iMaterialsManageService.getMaterialsManage();
    }

    @PostMapping("/mm/mid")
    public List<MaterialsManage> findMaterials(@RequestBody MaterialsManage materialName){
        log.info("参数值{}",materialName);
        return iMaterialsManageService.findMaterials(materialName.getMaterialName());
    }

    @Autowired
    IMaterialsManageService materialsManageService;

    @PostMapping("/materials-manage/save")
    public boolean save(@RequestBody MaterialsManage materialsManage) {
        return materialsManageService.save(materialsManage);
    }

    @GetMapping("/materials-manage/selectAll")
    public List<MaterialsManage> selectAll() {
        return materialsManageService.selectAll();
    }

    @GetMapping("/materials-manage/selectPage")
    public Page<MaterialsManage> selectPage(
            @RequestParam int page,
            @RequestParam int size,
            @RequestParam(required = false) String category) {
        return materialsManageService.selectPage(page, size, category);
    }

    @GetMapping("/materials-manage/lowStock")
    public List<MaterialsManage> getLowStockMaterials() {
        return materialsManageService.getLowStockMaterials(10);
    }

}
